package com.maiji.cloud.controller.smartprogram;

import com.maiji.cloud.controller.BaseController;
import com.maiji.cloud.request.BaseDataReqDto;
import com.maiji.cloud.request.login.XCXBindTelReqData;
import com.maiji.cloud.request.login.XCXLoginReqData;
import com.maiji.cloud.response.BaseDataResDto;
import com.maiji.cloud.response.login.XCXLoginResData;
import com.maiji.cloud.utils.Unlogin;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = {"微信小程序登录模块"})
@RequestMapping("/wx/")
public class WXLoginController  extends BaseController {

    @Unlogin
    @ApiOperation(value = "获取OpenId和SessionKey")
    @PostMapping("/login")
    public BaseDataResDto<XCXLoginResData> logon (@RequestBody BaseDataReqDto<XCXLoginReqData> baseDataReqDto) {
        return restTemplate.postForObject(REST_URL_APPLOGIN + "/wx/login", baseDataReqDto, BaseDataResDto.class);
    }

    @Unlogin
    @ApiOperation(value = "微信小程序绑定手机号")
    @PostMapping("/bindTel")
    public BaseDataResDto<String> bindTel (@RequestBody BaseDataReqDto<XCXBindTelReqData> baseDataReqDto) {
        return restTemplate.postForObject(REST_URL_APPLOGIN + "/wx/bindTel", baseDataReqDto, BaseDataResDto.class);
    }

    @Unlogin
    @ApiOperation(value = "微信小程序登录")
    @PostMapping("/openidLogin")
    public BaseDataResDto<String> openidLogin (@RequestBody BaseDataReqDto<String> baseDataReqDto) {
        return restTemplate.postForObject(REST_URL_APPLOGIN + "/wx/openidLogin", baseDataReqDto, BaseDataResDto.class);
    }

}
